<template>
  <section class="cms-body" v-loading="loading">
    <!-- 返回组件 -->
    <cms-back></cms-back>
    <el-form ref="form" :model="dataInfo" :rules="rules" class="cms-form" label-width="162px">

      <el-form-item label="姓名" class="flex-50 " prop="userName">
        <el-input class="cms-width" v-model="dataInfo.userName" :disabled="isType('update')"></el-input>
      </el-form-item>

      <el-form-item label="手机号码" class="flex-50 " prop="mobile">
        <el-input class="cms-width" v-model="dataInfo.mobile" :disabled="isType('update')"></el-input>
      </el-form-item>

      <el-form-item label="公司名称" class="flex-50 " prop="companyName">
        <el-input class="cms-width" v-model="dataInfo.companyName" :disabled="isType('update')"></el-input>
      </el-form-item>

      <el-form-item label="公司所在地" class="flex-50 " prop="companyAddress">
        <el-input class="cms-width" v-model="dataInfo.companyAddress" :disabled="isType('update')"></el-input>
      </el-form-item>

      <el-form-item label="处理状态" class="flex-50" prop="state">
        <el-radio-group v-model="dataInfo.state">
          <el-radio :label="0">未处理</el-radio>
          <el-radio :label="1">已处理</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="备注" class="flex-50 " prop="remark">
        <el-input class="cms-width" v-model="dataInfo.remark"></el-input>
      </el-form-item>

      <!-- 按钮组 -->
      <div class="form-footer">
        <el-button type="warning" v-if="isType('save')" @click="add(true)" v-perms="'/advApply/save'">提交并继续添加</el-button>
        <el-button type="primary" v-if="isType('save')" @click="add(false)" v-perms="'/advApply/save'">提交</el-button>
        <el-button type="primary" v-if="isType('update')" @click="update()" v-perms="'/advApply/update'">修改</el-button>
        <el-button type="info" @click="$reset">重置</el-button>
        <span class="gray" v-if="isType('save')">选择“提交并继续添加”按钮会停留在添加页面；选择“提交”按钮后将跳转到对应的列表页</span>
      </div>

    </el-form>

  </section>
</template>
<script>
  import axios from "axios/index";
  import va from "@/rules";
  import formMixns from "@/mixins/form";

  export default {
    mixins: [formMixns], //普通表单变量
    data() {
      return {
        rules: {//校验规则

        },
        dataInfo: {},
      };
    },
    methods: {
      getDataInfo(id, type) {
        if (type == 'update') {
          axios.post(this.$api.advApplyGet, {advApplyId: id}).then(res => {
            console.log(res)
            this.dataInfo = res.body;
          }).catch(err => {
            console.log(err);
          });
        }
        this.loading = false;
      },
      update() {
        this.updateDataInfo(this.$api.advApplyUpdate, this.dataInfo, "pageList");
      },
      add(state) {
        this.saveDataInfo(state, this.$api.advApplySave, this.dataInfo, "pageList");
      },
    },
    created() {
      this.getDataInfo(this.id, this.type);
    }
  };
</script>

<style>
</style>
